﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Flight_Reservation.DataLayer;

namespace Flight_Reservation.Algrithm
{
    class Node
    {
        public bool Visited { get; set; }
        public double TotalPrice { get; set; }
        public List<Node> Adjecencies { get; private set; }
        public int NoOfStops { get; set; }
        public Airport Airport { get; set; }
        public List<Edge> Edges { get; private set; }
        public Edge CameFromEdge{get; set;}

        public Node(Airport airport)
        {
            Airport = airport;
            Visited = false;
            TotalPrice = -1;
            NoOfStops = -1;
            Adjecencies = new List<Node>();
            Edges = new List<Edge>();
        }

        public int Compare(Node node)
        {
            return TotalPrice.CompareTo(node.TotalPrice);
        }

        public bool EqualAirport(Node node)
        {
            return Airport.AirportCode.Equals(node.Airport.AirportCode);
        }

        public void Reset()
        {
            Visited = false;
            CameFromEdge = null;
            TotalPrice = -1;
            NoOfStops = -1;
            Adjecencies = new List<Node>();
            Edges = new List<Edge>();
            Airport = null;
        }

        private List<Node> GetAdjecencies(Node node)
        {
            List<Node> nodes = new List<Node>();
            foreach (Edge edge in Edges)
            {
                nodes.Add(node.Airport.AirportCode == edge.FirstNode.Airport.AirportCode ? edge.SecondNode : edge.FirstNode);
            }
            return nodes;
        }

        
    }
}
